package com.novellotus.iov.carvice.adapter;

import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.novellotus.iov.carvice.R;
import com.novellotus.iov.carvice.bean.RxFn;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Rich on 2018/1/22.
 */

public class RoleHelpAdapter extends RecyclerView.Adapter<RoleHelpAdapter.RoleHelpHolder> {

    private ArrayList<RxFn> rxFnList;

    public RoleHelpAdapter(ArrayList<RxFn> rxFnList) {
        this.rxFnList = rxFnList;
    }

    @Override
    public RoleHelpHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_role_help, parent,false);
        return new RoleHelpHolder(view);
    }

    @Override
    public void onBindViewHolder(RoleHelpHolder holder, int position) {

        if (rxFnList.get(position) != null) {
            holder.tv_role_name.setText(rxFnList.get(position).getRoleName());
            holder.tv_role_des.setText(rxFnList.get(position).getDescription());
            StringBuffer stringBuffer = new StringBuffer();
            for (RxFn.MenusBean menusBean : rxFnList.get(position).getMenus()) {
                stringBuffer.append("#" + menusBean.getName());
            }
            holder.tv_role.setText(stringBuffer.toString());
        }

    }

    @Override
    public int getItemCount() {
        return rxFnList.size();
    }

    class RoleHelpHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_role_name)
        TextView tv_role_name;
        @BindView(R.id.tv_role_des)
        TextView tv_role_des;
        @BindView(R.id.tv_role)
        TextView tv_role;

        RoleHelpHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
